﻿@inject FwProject.Shop.Views.WebRootUrl WebRootUrl
@using FwProject.Shop.Dto
@using FwProject.ShoppingMall.Shop
@model ShopTypeInput
<style>
    .layui-table tr th, .layui-table tr td {
        text-align: center;
        padding: 9px 15px !important
    }

    .layui-form {
        padding: 15px;
    }

    .search-suggest .content {
        max-height: 300px;
        overflow-y: scroll;
    }

    .search-suggest {
        z-index: 19891020;
    }

    .hidden {
        display: none;
    }
</style>
@section styles{
    <link href="~/css/search-suggest.min.css" rel="stylesheet" />
}
<form id="form0" class="layui-form layui-form-pane" action="@Url.Action("Edit",new { id=ViewBag.Id })" method="post" novalidate="novalidate" data-ajax="true" data-ajax-success="ReloadAjaxCallbackgoback" data-ajax-failure="FailureAjaxCallback" data-ajax-method="Post" role="form" lay-filter="form1" style="margin-bottom: 80px;">
    <div class="layui-form-item">
        @Html.LabelFor(o => o.TypeName, new { @class = "layui-form-label" })
        <div class="layui-input-block">
            @Html.TextBoxFor(o => o.TypeName, new { @class = "layui-input", @lay_verify = "required" })
            @Html.ValidationMessageFor(o => o.TypeName)
        </div>
    </div>
    <div class="layui-form-item">
        @Html.LabelFor(o => o.TypeImg, new { @class = "layui-form-label" })
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="up_btn" style="margin-left:10px;">上传图片</button>
            <img src="@(string.IsNullOrEmpty(Model.TypeImg)?"~/images/默认图.png": WebRootUrl.WebImageRootUrl()+ Url.Content(Model.TypeImg))" id="up_img" width="30" height="30" />
            <input type="hidden" name="TypeImg" id="TypeImg" value="@Model.TypeImg" />
        </div>
    </div>
    <div class="layui-form-item">
        @Html.LabelFor(o => o.Isactive, new { @class = "layui-form-label" })
        <div class="layui-input-block">
            <input type="radio" name="Isactive" value="true" title="是" @(Model.Isactive ? "checked" : "")>
            <input type="radio" name="Isactive" value="false" title="否" @(Model.Isactive ? "" : "checked")>
        </div>
    </div>
    @if (Model.Parentid.HasValue)
    {
        <div class="layui-form-item">
            @Html.LabelFor(o => o.Parentid, new { @class = "layui-form-label" })
            <div class="layui-input-block">
                @Html.DropDownListFor(o => o.Parentid, ViewBag.Parent as IEnumerable<SelectListItem>)
                @Html.ValidationMessageFor(o => o.Parentid)
            </div>
        </div>
    }
    else
    {
        @Html.HiddenFor(o => o.Parentid)
    }
    <div class="layui-form-item">
        @Html.LabelFor(o => o.ProductTypeid, new { @class = "layui-form-label" })
        <div class="layui-input-block">
            <input type="text" id="search-productType" value="@ViewBag.ProductTypeName" class="layui-input" placeholder="请选择类型"  autocomplete="off">
            <input type="text" class="layui-input hidden" id="ProductTypeid" name="ProductTypeid" value="@(ViewBag.ProductTypeName!=null?Model.ProductTypeid:Guid.Empty)" lay-verify="productType" />
            @*@Html.TextBoxFor(o => o.ProductTypeid, new { @class = "hidden" })*@
            @Html.ValidationMessageFor(o => o.ProductTypeid)
        </div>
    </div>
    <div class="layui-form-item">
        @Html.LabelFor(o => o.Orders, new { @class = "layui-form-label" })
        <div class="layui-input-block">
            @Html.TextBoxFor(o => o.Orders, new { @class = "layui-input", @number = "number" })
            @Html.ValidationMessageFor(o => o.Orders)
        </div>
    </div>

    <div class="layui-layer-btn layui-layer-btn-" style="padding:8px 12px;z-index:1000;position: fixed;bottom:0;left: 1px;width: 98%;height: 50px; background:rgba(230,230,230,0.8)">
        <a id="save" class="layui-layer-btn0" type="submit" lay-submit="" lay-filter="saveprops">保存</a>
    </div>
</form>
@section scripts{
    <script src="~/js/main.js"></script>
    <script src="~/js/search-suggest.min.js"></script>
    <script type="text/javascript">
        $('#search-productType').on('blur', function () {
            if ($(this).val() == "" || $(this).val() == null) {
                $('#ProductTypeid').val("");
            }
        })

        var form, layer, layedit, upload;
        layui.use(['form', 'layedit', 'layer', 'upload'], function () {
            layedit = layui.layedit;
            form = layui.form;
            layer = layui.layer;
            upload = layui.upload;
            //自定义验证规则
            form.verify({
                required: function (value) {
                    if (value == "") {
                        return '必填项不能为空';
                    }
                },
                productType: function (value) {
                    if (value == "00000000-0000-0000-0000-000000000000") {
                        return '请先选择一个类型';
                    }
                }
            });

            form.on('radio', function (data) {
                if (data.value == "文字") {
                    $('.upImg').hide();
                } else {
                    $('.upImg').show();
                }
            });


             var uploadInst = upload.render({
                 elem: '#up_btn' //绑定元素
                 , url: '/ShopType/UploadImage' //上传接口
                 ,done: function (res) {
                  if (res.success) {
                      var img = "@WebRootUrl.WebImageRootUrl()/uploads/temp/shopType/";
                      $('#TypeImg').val(res.result)
                      $('#up_img').attr("src", img + res.result)
                        }
                    }
                    , error: function () {
                        //请求异常回调
                    }
                });


        })
        var search = $("#search-productType").searchSuggest({
            url: "/Genre/GetSearchSuggest?keyword=", /*优先从url ajax 请求 json 帮助数据*/
            jsonp: null,
            width: 200,   /*提示框的宽度，缺省为输入框的宽度相同*/
            topoffset: 16,  /*提示框与输入框的距离，缺省为5*/
            style: 'list',
            cssFile: '/css/search-suggest.min.css',
            selectCallback: function (d) {
                $("#ProductTypeid").val(d.id);
            }
        });

        function ReloadAjaxCallbackgoback(data, successInfo) {
            if (data.success) {
                parent.layer.msg('保存成功！')
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭当前iframe页面
            } else {
                layer.msg('保存失败：' + successInfo);
            }
        }


        $('#save').on('click', function () {
            $('#form0').submit();
        });

        $('#form0 table').on('click', '.del', function () {
            $(this).parent().parent().remove();
            var trs = $('#form0 tbody').find('tr');
            if (trs.length > 0) {
                for (var i = 0; i < trs.length; i++) {
                    $(trs[i]).find('#Spcevalue').attr("name", "ProductSpcevalues[" + i + "].Spcevalue");
                    $(trs[i]).find('#Spcevalueico').attr("name", "ProductSpcevalues[" + i + "].Spcevalueico");
                }
            }
        });
    </script>
}

